package com.roger.myHome.controller;

import com.roger.myHome.aspect.AuthAnnotation;
import com.roger.myHome.service.ReportService;
import com.roger.myHome.util.UserHelper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

@Controller
@RequestMapping("/report")
@Slf4j
public class ReportController {

    @Resource
    private ReportService reportService;

    @Resource
    private UserHelper userHelper;

    /**
     * 血糖波动曲线图
     * @return
     */
    @GetMapping("/bloodSugarCurveReport")
    @ResponseBody
    @AuthAnnotation()
    public String getBloodSugarReport(HttpServletRequest request){
        log.info("[{}],[{}]",userHelper.getLoginUser(request).getUsername(),"ReportController.bloodSugarCurveReport");
        return reportService.getBloodSugarCurveReport();
    }

    /**
     * 血糖异常波动曲线图
     * @return
     */
    @GetMapping("/bloodSugarExceptionCurveReport")
    @ResponseBody
    public String getBloodSugarExceptionReport(HttpServletRequest request){
        log.info("[{}],[{}]",userHelper.getLoginUser(request).getUsername(),"ReportController.bloodSugarExceptionCurveReport");
        return reportService.getBloodSugarExceptionCurveReport();
    }

    /**
     * 血糖统计饼图
     * @return
     */
    @GetMapping("/bloodSugarPieReport")
    @ResponseBody
    public String bloodSugarPieReport(HttpServletRequest request){
        log.info("[{}],[{}]",userHelper.getLoginUser(request).getUsername(),"ReportController.bloodSugarPieReport");
        return reportService.getBloodSugarPieReport();
    }

    /**
     * 消费统计图
     * @return
     */
    @GetMapping("/expenseColumnReport")
    @ResponseBody
    public String expenseColumnReport(HttpServletRequest request){
        log.info("{},{}",userHelper.getLoginUser(request).getUsername(),"ReportController.expenseColumnReport");
        return reportService.getExpenseColumnReport(userHelper.getLoginUser(request).getId());
    }



    @GetMapping("/bloodSugarMeasureTimes")
    @ResponseBody
    public String bloodSugarMeasureTimes(HttpServletRequest request){
        log.info("[{}],[{}]",userHelper.getLoginUser(request).getUsername(),"ReportController.bloodSugarMeasureTimes");
        return reportService.bloodSugarMeasureTimes();
    }

    @GetMapping("/getAvgExpense")
    @ResponseBody
    public String getAvgExpense(HttpServletRequest request){
        log.info("[{}],[{}]",userHelper.getLoginUser(request).getUsername(),"ReportController.getAvgExpense");
        Long userId = userHelper.getLoginUser(request).getId();
        return reportService.getAvgExpense(userId);
    }

    @GetMapping("/morningBloodSugarReport")
    @ResponseBody
    public String morningBloodSugarReport(HttpServletRequest request){
        log.info("[{}],[{}]",userHelper.getLoginUser(request).getUsername(),"ReportController.morningBloodSugarReport");
        return reportService.morningBloodSugarReport();
    }

    @GetMapping("/getBloodSugarByIndex/{index}")
    @ResponseBody
    public String getBloodSugarByIndex(HttpServletRequest request, @PathVariable int index){
        log.info("[{}],[{}]","ReportController.getBloodSugarByIndex", index);
        return reportService.getBloodSugarByIndex(index);
    }

}
